package com.qimo.zzy.controller;

import com.qimo.zzy.service.ProductService;
import jakarta.annotation.Resource;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

@CrossOrigin//跨域
@RestController//遵循RestFul
@RequestMapping("/qimo/Product/")
public class ProductController {


    @Resource
    private RedisTemplate<String, String> redisTemplate;//Redis工具类

    @Resource
    ProductService productService;

    /**
     * 获取商品列表
     *
     * @param detail
     * @param start
     * @param cnt
     * @param sort
     * @return
     */
    @GetMapping("getProductList")
    private String getProductList(
            @RequestParam(value = "detail",required = false) String detail,
            @RequestParam(value = "start",required = false) int start,
            @RequestParam(value = "cnt",required = false) int cnt,
            @RequestParam(value = "sort",required = false) int sort
    ) {
        return productService.getProductList(detail, start, cnt, sort);
    }

    /**
     * 获取商品详情
     *
     * @param pid
     * @return
     */
    @GetMapping("getProductDetail")
    private String getProductDetail(
            @RequestParam("pid") int pid
    ) {
        return productService.getProductDetail(pid);
    }

    /**
     * 根据pid查询所有的图片
     * @param pid
     * @return
     */
    @GetMapping("getProductImage")
    private String getProductImage(
            @RequestParam("pid") int pid
    ) {
        return productService.getProductImage(pid);
    }
}
